package com.english.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * Web配置类
 * 配置静态资源映射
 * 
 * @author wlq
 * @since 2025-08-06
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Value("${upload.banner.path:src/main/resources/static/images/banner}")
    private String bannerPath;

    @Value("${upload.image.path:upload/images}")
    private String imagePath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 配置轮播图静态资源映射
        Path bannerPathObj = Paths.get(bannerPath);
        String bannerLocation = "file:" + bannerPathObj.toAbsolutePath().toString().replace("\\", "/") + "/";
        
        registry.addResourceHandler("/images/banner/**")
                .addResourceLocations(bannerLocation);
        
        // 配置通用图片静态资源映射
        registry.addResourceHandler("/images/**")
                .addResourceLocations("file:/www/wwwroot/english/upload/images/")
                .addResourceLocations("file:/www/wwwroot/english/upload/");
        
        // 配置其他静态资源
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");
    }
} 